package com.hardydou.pattern.singleton;


import java.util.concurrent.atomic.AtomicInteger;

/**
 * 单例模式
 * <p>
 * 懒汉式
 *
 * @author hardy
 */
public class LazyLoadSingleton {

    private  static AtomicInteger count = new AtomicInteger(0);

    public static LazyLoadSingleton instance;

    private static boolean initOk = false;

    private LazyLoadSingleton() {
        count.getAndAdd(1);
        try {
            Thread.sleep(500L);
        } catch (Exception e) {

        }

        initOk=true;

    }

    public synchronized static LazyLoadSingleton getInstance() {
        if (instance == null) {
            instance = new LazyLoadSingleton();
        }

        return instance;
    }

    public static int getCount() {
        return count.get();
    }
    public static boolean hasInit() {
        return initOk;
    }
}
